import axios from "axios";
import * as api from "../api/gw/index.js";
import store from "../store";
export default function (gen) {
    let options = {
        method: "get",
        // url: api.service_host + api.config_params + `/${window.api.enterpriseCode}`
        url: window.api.base_host + api.CONFIG_PARAMS + `/${window.api.enterpriseCode}`
    }
    return new Promise((resolve, reject) => {
        axios(options).then(data => {
            // console.log("配置相关的参数", data);
            // return new Promise((resolve, reject) => {
            if (data.status === 200 && data.data.returnCode === 1 && data.data.data[0]) {
                console.log("data-----data", data);
                sessionStorage.setItem("configParams", JSON.stringify(data.data.data[0]));
                window.getConfigParams =  data.data.data[0]
                // callback && callback();
                // gen.next();
                if (data.data.data[0].runStatus) {
                    //判断商城是否是开启状态
                    setSpecialTemplateParams(data.data.data[0].templateConfigList);
                    // console.log("data.data.data[0].runStatus", data.data.data[0].runStatus)
                    resolve(true);
                } else {
                    resolve(false);
                }
            } else {
                resolve(false);
                console.log("接口请求失败");
            }
            // });
        }).catch(err => {
            resolve(false);
            console.log("接口请求失败", err);
        });
    });

}

//设置保存新增页面的方法
function setSpecialTemplateParams(list) {
    let exits = false;
    for (let item of list) {
        // tpState为特殊的
        // tpDesc === specialtemplateforaddpages
        if (item.tpDesc === "specialtemplateforaddpages") {
            exits = true;
            store.commit("gw/setSpecialTemplateParams", item);
            store.commit("gw/setNeedUploadSpecialTemplate", false);
        }
    }
    if (!exits) {
        store.commit("gw/setSpecialTemplateParams", {});
        store.commit("gw/setNeedUploadSpecialTemplate", true);
    }
}
